from datetime import datetime

from sqlalchemy import Column, Integer, String, CHAR, DECIMAL

from app.models.base import Base, db


class report_source_info(Base):
    __tablename__ = 'report_source_info'
    id = Column(Integer, primary_key=True, autoincrement=True)
    order_number = Column(String(80), default='')
    source_type = Column(String(30), default='local')
    source = Column(String(1000), default='')
    rate = Column(DECIMAL(5, 2), default=0)

    def keys(self):
        return ['id', 'order_number', 'source_type', 'source', 'rate', 'title', 'author']

    @property
    def title(self):
        return self.source.split('- ')[0]

    @property
    def author(self):
        return self.source.split('- ')[1].split(' -')[0]
